﻿using SpyApp.Models.BaseCommon;
using SpyApp.Models.BaseCommon.Enum;
using SpyApp.Models.EntytiRepossitory;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Web;
using System.Web.WebPages.Html;

namespace SpyApp.Models
{
    public class AccountModel
    {
        
        /// <summary> Change Password model </summary>
        public class ChangePasswordModel
        {
            [Required]
            [DataType(DataType.Password)]
            [Display(Name = "Current password")]
            public string OldPassword { get; set; }

            [Required]
            [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
            [DataType(DataType.Password)]
            [Display(Name = "New password")]
            public string NewPassword { get; set; }

            [DataType(DataType.Password)]
            [Display(Name = "Confirm new password")]
            [Compare("NewPassword", ErrorMessage = "The new password and confirmation password do not match.")]
            public string ConfirmNewPassword { get; set; }
        }

        public class LoginModel
        {
            [Required(ErrorMessage = "Please provide Email", AllowEmptyStrings = false)]
            [Display(Name = "Email")]
            //ErrorMessage = "Don't use special character"[RegularExpression("[a-zA-Z0-9]*", ErrorMessage = "Don't use special character")]
            //[RegularExpression((@"^([0-9a-zA-Z]([\+\-_\.][0-9a-zA-Z]+)*)+@(([0-9a-zA-Z][-\w]*[0-9a-zA-Z]*\.)+[a-zA-Z0-9]{2,3})$"), ErrorMessage = "Don't use special character")]
            [EmailAddress(ErrorMessage = "Invalid Email Address")]
            public string Email { get; set; }

            [Required]
            [DataType(DataType.Password)]
            [Display(Name = "Password")]
            public string Password { get; set; }

            [Display(Name = "Remember me")]
            public bool RememberMe { get; set; }
        }

        public class RegisterModel
        {
            [Required(ErrorMessage = "Email can't null", AllowEmptyStrings = false)]
            [Display(Name = "Email")]
            [EmailAddress(ErrorMessage = "Invalid Email Address")]
            public string Email { get; set; }

            [Required]
            [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)]
            [DataType(DataType.Password)]
            [Display(Name = "Password")]
            public string Password { get; set; }

            [DataType(DataType.Password)]
            [Display(Name = "Confirm password")]
            [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")]
            public string ConfirmPassword { get; set; }

            [Required(ErrorMessage = "Captcha can't null")]
            [Display(Name = "Let's math")]
            public string Captcha { get; set; }            
        }

        //public class AdminView
        //{
        //    [Display(Name="Id")]
        //    public string Id { get; set; }
        //    [Display(Name = "Password")]
        //    public string PassWord { get; set; }
        //    [Display(Name = "Username")]
        //    public string UserName { get; set; }

        //    [Display(Name = "User in roles")]
        //    public List<Roles> UserInRoles
        //    {
        //        get
        //        button, input[type="button"], input[type="input"], input[type="submit"]{
        //            if (!string.IsNullOrEmpty(this.Id))
        //            {
        //                return RolesExt.GetListRoleByUserId(this.Id, null, new List<Roles>()).ToList();
        //            }
        //            return new List<Roles>();
        //        }
        //        set
        //        {
        //            _UserInRoles = value;
        //        }
        //    }
        //    List<Roles> _UserInRoles;

        //    [Display(Name = "Active invation code")]
        //    public string ActiveInvationCode { get; set; }
        //    [Display(Name = "User status")]
        //    public string UserStatus { get; set; }
        //    [Display(Name = "Status")]
        //    public string Status { get; set; }
        //    [Display(Name = "Last modifined")]
        //    public DateTime LastModifined { get; set; }
        //    [Display(Name = "User type")]
        //    public string UserType { get; set; }

        //    [Display(Name = "Age")]
        //    [Range(0, 130, ErrorMessage = "Age must between 0 and 130")]
        //    public int Age { get; set; }
        //    [Display(Name = "Total login")]
        //    [Range(0, int.MaxValue, ErrorMessage = "Invalid value")]
        //    public int TotalLogin { get; set; }


        //    public static List<AdminView> Convert(List<User> listUser)
        //    {
        //        return listUser.Select(u => new AdminView()
        //        {
        //            Id = u.Id,
        //            UserName = u.UserName,
        //            PassWord = u.PassWord,
        //            ActiveInvationCode = u.ActiveInvationCode,
        //            Age = u.Age,
        //            LastModifined = u.LastModifined,
        //            Status = u.Status.ToString(),
        //            TotalLogin = u.TotalLogin,
        //            UserStatus = u.UserStatus.ToString(),
        //            UserType = u.UserType.ToString()
        //        }).ToList();
        //    }
        //}

        public class AdminEdit
        {
            public AdminEdit()
            {

            }

            public AdminEdit(User user) : this()
            {
                // TODO: Complete member initialization
                Id = user.Id;
                UserName = user.UserName;
                PassWord = user.PassWord;
                ActiveInvationCode = user.ActiveInvationCode;
                Age = user.Age;
                TotalLogin = user.TotalLogin;
                UserStatus = user.UserStatus;
                Status = user.Status;
                UserType = user.UserType;

                // set selection user in role
                List<Roles> listRoleSelect = user.UserInRoles;
                if (listRoleSelect != null)
                {
                    List<String> listRoleIdSelect = listRoleSelect.Select(i => i.Id).ToList();
                    SelectListUtils.SelectListItem_SetSelected(listRoleIdSelect, UserInRoles);
                }
            }

            [Display(Name = "Id")]
            public string Id { get; set; }
            [Display(Name = "Username")]
            public string UserName { get; set; }
            [Display(Name = "Password")]
            public string PassWord { get; set; }
            [Display(Name = "Active invation code")]
            public string ActiveInvationCode { get; set; }

            [Display(Name = "Age")]
            [Range(0, 130, ErrorMessage = "Age between 0 and 130")]
            public int Age { get; set; }
            [Display(Name = "Total login")]
            [Range(0, int.MaxValue, ErrorMessage = "Invalid value")]
            public int TotalLogin { get; set; }

            [Display(Name = "User status")]
            public DBEntity.UserStatus UserStatus { get; set; }
            [Display(Name = "Status")]
            public DBEntity.ObjectStatus Status { get; set; }
            [Display(Name = "User type")]
            public DBEntity.UserType UserType { get; set; }

            public List<System.Web.Mvc.SelectListItem> AllUserStatus
            {
                get
                {
                    return ConvertUtils.EnumToSelectListItem(typeof(DBEntity.UserStatus));
                }
            }
            public List<System.Web.Mvc.SelectListItem> AllObjectStatus
            {
                get
                {
                    return ConvertUtils.EnumToSelectListItem(typeof(DBEntity.ObjectStatus));
                }
            }
            public List<System.Web.Mvc.SelectListItem> AllUserType
            {
                get
                {
                    return ConvertUtils.EnumToSelectListItem(typeof(DBEntity.UserType));
                }
            }

            [Display(Name = "User in roles")]
            public List<System.Web.Mvc.SelectListItem> UserInRoles
            {
                get
                {
                    if (_UserInRoles == null)
                    {
                        // lấy hết userRoles
                        var listRole = RolesExt.GetAllRoles(null, new List<Roles>());
                        _UserInRoles = listRole.Select(i => new System.Web.Mvc.SelectListItem()
                            {
                                Value = i.Id,
                                Text = i.RoleName
                            }).ToList();
                    }
                    return _UserInRoles;
                }
                set
                {
                    _UserInRoles = value;
                }
            }
            List<System.Web.Mvc.SelectListItem> _UserInRoles;
            IEnumerable<Roles> listRoleSelect;


            public User ToUser()
            {
                List<string> listRoleId = this.UserInRoles.Where(i => i.Selected).Select(i => i.Value).ToList();

                User user = new User();
                user.Id = this.Id;
                user.UserName = this.UserName;
                user.PassWord = this.PassWord;
                user.ActiveInvationCode = this.ActiveInvationCode;
                user.Age = this.Age;
                user.TotalLogin = this.TotalLogin;
                user.UserStatus = this.UserStatus;
                user.Status = this.Status;
                user.UserType = this.UserType;
                user.UserInRoles = RolesExt.GetListRoleByListId(listRoleId, null, new List<Roles>()); 

                return user;
            }
        }
        
        public class LocationModel
        {
            [Required(ErrorMessage = "Email can't null")]
            [DataType(DataType.EmailAddress)]
            public string Email { get; set; }

            [Required(ErrorMessage = "DeviceId can't null")]
            [DataType(DataType.Text)]
            public string DeviceId { get; set; }
                  
            public double Longitude { get; set; }
            public double Latitude { get; set; }
            public DateTime DateTimeCheck { get;set; }
        }
        
        public class WebServiceAddNewMsg
        {
            public string UserId { get; set; }
            public string DeviceId { get; set; }
            public string MessageText { get; set; }
            public string Uuid { get; set; }
            public int MessageType { get; set; }
            public string NumberSendReceive { get; set; }
            public DateTime DateTime { get; set; }
            public int Type { get; set; }
        }

        public class WebServiceRequest
        {

            [Required(ErrorMessage = "Please provide Email", AllowEmptyStrings = false), MaxLength(50)]
            [DataType(DataType.EmailAddress)]            
            public string UserName { get; set; }
            public string PassWord { get; set; }
            public string Imei { get; set; }
            public string Sn { get; set; }
            public string DeviceName { get; set; }
            public string OsVersion { get; set; }
            public string OsBrand { get; set; }
            public string ScreenSize { get; set; }
            public string AppVersion { get; set; }
            public string AppInstalledOn { get; set; }
        }

        public class WebServiceRegister
        {

            [Required(ErrorMessage = "Email can't null", AllowEmptyStrings = false)]
            [Display(Name = "Email")]
            [EmailAddress(ErrorMessage = "Invalid Email Address")]
            public string UserName { get; set; }

            [Required]
            [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 3)]
            [DataType(DataType.Password)]
            [Display(Name = "Password")]
            public string PassWord { get; set; }
           
        }

        public class WebServiceResult
        {
            public string Status { get; set; }
            public string Id { get; set; }
            public string Uuid { get; set; }
            public string DeviceId { get; set; }
            public string Message { get; set; }
        }

        public class WebServiceLocation
        {
            public string deviceId { get; set; }
            public DateTime formDate { get; set; }
            public DateTime toDate { get; set; }
            public string userId { get; set; }
        }

        public class RegisNotifitration
        {
            public string deviceId { get; set; }            
            public string userName { get; set; }
            public string registrationId { get; set; }
        }
        public class PushNotifitration
        {
            public string deviceId { get; set; }
            public string userName { get; set; }
            public string Message { get; set; }
        }

    }
}